/*
 *
 *  RYMOS
 *  Copyright (C) 2003 - 2012 Roberto Rodriguez 
 *
 *  This program is free software; you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation; either version 2 of the License, or 
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License 
 *  along with this program; if not, write to the Free Software 
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * contact me by e-mail <prfiredragon@gmail.com>
 *
 */



/*********************************************************************/
/** \internal
*	
*		Draws a vertical Line.
*	\param x 	x-Position
*	\param y1	y1-Position
*	\param y2	y2-Position
*	\param c	Color
*
* Draws a vertical Line from (x,y1) to (x,y2) wich is colored c.
*
*//*******************************************************************/
void drawVLine(int x,int y1, int y2, int c){
	int dy;
	for(dy=y1;dy<y2;dy++){
	    SetPixel(x,dy,c);
 	}
}

/*********************************************************************/
/** \internal
*	
*		Draws a horizontal Line.
*	\param x1	x1-Position
*	\param x2	x2-Position
*	\param y	y-Position
*	\param c	Color
*
* Draws a horizontal Line from (x1,y) to (x2,y) wich is colored c.
*
*//*******************************************************************/
void drawHLine(int x1,int x2, int y, int c){
	int dx;
	for(dx=x1;dx<x2;dx++){
	    SetPixel(dx,y,c);
 	}
}
/*********************************************************************/
/**
*
*		Draws a Line.
*	Uses Midpoint Line Algo. from Bresenham.
* \note
*		Vertical and horizontal Lines are 
*
*//*******************************************************************/
void drawLine(int x1, int y1, int x2, int y2,int c){
 	int buf;
	int dx,dy,incrE,incrNE,d,x,y;

	if(x2 < x1){
		buf=x1;
		x1=x2;
		x2=buf;
	}	
	if(y2 < y1){
		buf=y1;
		y1=y2;
		y2=buf;
	}	
	
	if(x1==x2){
		drawVLine(x1,y1,y2,c);
		return;
	}	
	if(y1==y2){
		drawHLine(x1,x2,y1,c);
		return;
	}	
	
	dx = x2-x1;
	dy= y2-y1;
	d=2*dy-dx;
	incrE=2*dy;
	incrNE=2*(dy-dx);
  x=x1;
	y=y1;
	SetPixel(x,y,c);
	while(x<x2){
		if(d<=0){
			d+=incrE;
			x++;
		}else{
			d+=incrNE;
			x++;
			y++;
		}
		SetPixel(x,y,c);		
	}		
}


